package com.xoa.plugin.workflow.workflowservice.imlp.lnsfplugin;

import com.xoa.dev.efficiency.model.FlowAbilityMonitor;
import com.xoa.plugin.workflow.workflowservice.WorkFlowService;
import com.xoa.util.ToJson;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Major_2 implements WorkFlowService {
    @Override
    public ToJson run(HttpServletRequest request) {
        String flowId=request.getParameter("flowId");
        String runId=request.getParameter("runId");
        List<String[]> yijian= LnsfUtil.init().getdubanyijian(LnsfUtil.init().getWorkNameValue(flowId,runId,"工作部署"));
        List<Map<String,String>> dataList=LnsfUtil.init().getFlowAbilityMonitorMapper().getData(Integer.parseInt(runId),2);
        if(dataList!=null&&dataList.size()>0){
            for(int i=0;i<dataList.size();i++){
                Map<String,String> data=dataList.get(i);
                FlowAbilityMonitor abilityMonitor=new FlowAbilityMonitor();
                abilityMonitor.setRunId(Integer.parseInt(runId));
                abilityMonitor.setUserId(data.get("USER_ID"));
                abilityMonitor.setDeptId(data.get("DEPT_ID"));
                String userName=data.get("USER_NAME");
                for(int j=0;j<yijian.size();j++){
                    if(yijian.get(j)[2].equals(userName)){
                        abilityMonitor.setWorkTitle(yijian.get(j)[0]);
                        abilityMonitor.setWorkDeadline(yijian.get(j)[3]);
                    }
                    abilityMonitor.setWorkType(3);
                    abilityMonitor.setUserType(5);
                    abilityMonitor.setDeptType(5);
                    abilityMonitor.setWorkStart(LnsfUtil.init().getSdf().format(new Date()));
                    abilityMonitor.setRunIdF(Integer.parseInt(data.get("PARENT_RUN")));
                    abilityMonitor.setRunTitleF(LnsfUtil.init().getWorkNameValue(flowId,runId,"工作事项"));
                    LnsfUtil.init().setData(abilityMonitor);
                }

            }
        }
        return null;
    }
}
